package com.yangtzeu.jwc.activity;

import android.R.anim;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.yangtzeu.jwc.utils.AllActivitys;
import com.yangtzeu.jwc.utils.ConfirmDialog;
import com.yangtzeu.jwc.utils.G;
import com.zhangdi.jwc.R;
import com.zjsx.lib.utils.T;

public class BaseActivity extends AppCompatActivity implements OnClickListener {
    AllActivitys activitys;

    View titleView;

    TextView tvLogo;
    TextView tvTitleLeft;
    TextView tvTitle;
    TextView tvTitleRight;
    TextView tvTitleRight2;
    ProgressBar pb_loading;
    ImageButton ib_option;

    Handler handler;

    ActionBar actionBar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        activitys = AllActivitys.getInstance();
        activitys.onCreate(this);

        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                handleMsg(msg);
            }
        };

        setView();
        actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        initData();
        initActionBar();
        initView();
        initListener();
        initAdapter();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            if (this instanceof MainActivity3) {
                if (ConfirmDialog.show(this, "提示", "是否前往教务处官网？")) {
                    Intent intent = new Intent();
                    intent.putExtra("title", "正在加载网页...");
                    intent.putExtra("url", G.NEW_JWC_HOME);
                    intent.setClass(this, NewsActivity.class);
                    startActivity(intent);
                }
                return true;
            } else {
                this.finish();
            }
        }
        return super.onOptionsItemSelected(item);
    }

    @SuppressLint("InflateParams")
    protected void setSimpleActionBar(String logoText, String leftTitleText, String titleText, String rightTitleText) {

    }

    public void setActionBarLayout(View view) {

    }

    public void setView() {

    }

    public void initData() {

    }

    public void initActionBar() {
        setSimpleActionBar(null, null, "长江大学教务处", null);
    }

    public void initView() {

    }

    public void initListener() {

    }

    public void initAdapter() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ib_logo:
                finish();
                break;
            case R.id.ll_logo:
                finish();
                break;
            default:
                break;
        }
    }

    public void handleMsg(Message msg) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        activitys.onDestroy(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        activitys.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        activitys.onResume(this);
    }

}
